<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>馆藏图书</title>
    <!--  引入核心皮肤-->
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <!--   引入核心js-->
    <script src="../../layui/layui.js"></script>
    <style>
        .layui-form-item  {width: auto;padding-right: 10px;line-height: 38px;}
    </style>
</head>
<body>
<div class="layui-container">
    <div class="layui-main">
        <div class="layui-form layui-form"  lay-filter="form">
            <div class="layui-form-item">
                <label class="layui-form-label required">账号名称</label>
                <div class="layui-input-block">
                    <input type="text" name="username" lay-verify="required" lay-reqtext="管理账号不能为空" placeholder="请输入管理账号"  value="teacher" class="layui-input">
                    <tip>填写自己管理账号的名称。</tip>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="tecname" lay-verify="required" lay-reqtext="不能为空" placeholder="请输入"  value="" class="layui-input">
                    <input type="hidden" name="tecid"  class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">手机</label>
                <div class="layui-input-block">
                    <input type="number" name="tel" lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">学院</label>
                <div class="layui-input-block">
                    <input type="text" name="institute" lay-verify="required" lay-reqtext="不能为空" placeholder="请输入"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">学院ID</label>
                <div class="layui-input-block">
                    <input type="text" name="collegeId" lay-verify="required" lay-reqtext="不能为空" placeholder="请输入"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input type="email" name="email" placeholder="请输入邮箱"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注信息</label>
                <div class="layui-input-block">
                    <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form','layer','jquery'], function () {
        var form = layui.form,
            layer = layui.layer;
        let $=layui.jquery;//定义组件
        $.ajax({
            type: "post",
            url: "../../teacher/selectOne",
            success: function (data) {
                console.log(data)
                form.val('form', {
                    collegeId: data.collegeId,
                    email: data.email,
                    institute: data.institute,
                    tecid: data.tecid,
                    tecname: data.tecname,
                    tel: data.tel
                })
                form.render();
            }

        });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            console.log(data)
            var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {
                $.post('../../teacher/updateOne',data.field
                   , function (flag) {
                    if (flag) {
                        layer.msg('修改个人信息成功', {icon: 6});
                    } else {
                        layer.msg('修改个人信息失败', {icon: 5});
                    }
                })
                layer.close(index);
            });
            return false;
        });

    });
</script>
</body>
</html>